#ifndef _BENCODE_H_
#define _BENCODE_H_

#include <stdlib.h>
#include <string.h>
#include <string>
#include <map>
#include <vector>

using namespace std;

/*******************************************************************************
* bType
*******************************************************************************/
enum bType
{
	B_DICTIONARY, B_LIST, B_STRING, B_INTEGER, B_UNDEFINED
};

/*******************************************************************************
* bItem
*******************************************************************************/
class bItem
{
public:
	bItem(bType itemtype) { m_itemtype = itemtype; }
	~bItem() { }
	bType GetType() { return m_itemtype; }
	int GetCharOffset() { return m_charoffset; }
protected:
	int m_charoffset;
private:
	bType m_itemtype;
};

/*******************************************************************************
* bDictionary
*******************************************************************************/
class bDictionary : public bItem
{
public:
	bDictionary(const char *bDictionary);
	~bDictionary();
	bItem* GetItemFromKey(const string key);
private:
	map<string, bItem*> m_dictionary;
};

/*******************************************************************************
* bList
*******************************************************************************/
class bList : public bItem
{
public:
	bList(const char *bList);
	~bList();
	bItem* GetItemFromIndex(int index);
	unsigned GetNumItems();
private:
	vector<bItem*> m_list;
};

/*******************************************************************************
* bString
*******************************************************************************/
class bString : public bItem
{
public:
	bString(const char *bString);
	~bString();
	string GetString();
	void GetByteString(char *dest);
	unsigned GetStringLength();
private:
	char *m_str;
	unsigned m_strlen;
};

/*******************************************************************************
* bInteger
*******************************************************************************/
class bInteger : public bItem
{
public:
	bInteger(const char *bInteger);
	~bInteger();
	int GetInteger();
private:
	int m_integer;
};

/*******************************************************************************
* bDecode
*******************************************************************************/
bItem* bDecode(const char *bStr);
//char* bEncode(const bItem *bItem);

#endif
